/**
* Copyright (c) 2024 Huawei Technologies Co., Ltd.
* This file is a part of the CANN Open Software.
* Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/

/*!
* \file matmul_macro_def.h
* \brief
*/
#ifndef IMPL_MATMUL_MATMUL_MACRO_DEF_H
#define IMPL_MATMUL_MATMUL_MACRO_DEF_H
#include "matmul_utils.h"
#include "matmul_macro_v220_impl.h"
#include "matmul_macro_v220_basic_impl.h"
#include "matmul_macro_v200_impl.h"
#include "modules/matmul_param.h"

namespace matmul {

/* **************************************************************************************************
 * MatmulMacroImpl                                             *
 * ************************************************************************************************* */
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG, MatmulVersion MM_VER>
struct MatmulMacroImpl {
    __aicore__ inline MatmulMacroImpl() {};
};

#if __CCE_AICORE__ >= 220
// CFG_NORM
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(CFG_NORM)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    static constexpr uint16_t GEMV_MODE = (A_TYPE::format == CubeFormat::VECTOR) ? 1 :
        ((A_TYPE::format == CubeFormat::SCALAR) ? 2 : 0);
    using PARAMS = MacroMatmul<L0cT, typename A_TYPE::T, typename B_TYPE::T, typename BIAS_TYPE::T,
        EnUnitFlag(MM_CFG), 0, GEMV_MODE>;
};
// CFG_MDL
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(CFG_MDL)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    static constexpr uint16_t GEMV_MODE = (A_TYPE::format == CubeFormat::VECTOR) ? 1 :
        ((A_TYPE::format == CubeFormat::SCALAR) ? 2 : 0);
    using PARAMS = MacroMatmul<L0cT, typename A_TYPE::T, typename B_TYPE::T, typename BIAS_TYPE::T,
        EnUnitFlag(MM_CFG), 0, GEMV_MODE>;
};
// CFG_IBSHARE_NORM
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(CFG_IBSHARE_NORM)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    static constexpr uint16_t GEMV_MODE = (A_TYPE::format == CubeFormat::VECTOR) ? 1 :
        ((A_TYPE::format == CubeFormat::SCALAR) ? 2 : 0);
    using PARAMS = MacroMatmul<L0cT, typename A_TYPE::T, typename B_TYPE::T, typename BIAS_TYPE::T,
        EnUnitFlag(MM_CFG), 0, GEMV_MODE>;
};
#elif __CCE_AICORE__ == 200
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(CFG_NORM)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    using PARAMS = MacroMatmulV200<L0cT, typename A_TYPE::T, typename A_TYPE::T>;
};
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(CFG_MDL)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    using PARAMS = MacroMatmulV200<L0cT, typename A_TYPE::T, typename A_TYPE::T>;
};
#endif

// MM_CFG_BB
template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, const MatmulConfig& MM_CFG>
struct MatmulMacroImpl<A_TYPE, B_TYPE, C_TYPE, BIAS_TYPE, MM_CFG, GetMatmulVersion(MM_CFG_BB)> {
    using L0cT = typename GetDstType<typename A_TYPE::T>::Type;
    __aicore__ inline MatmulMacroImpl() {};
    using PARAMS = MacroMatmulBasic<L0cT, typename A_TYPE::T, typename B_TYPE::T, typename BIAS_TYPE::T,
        BIAS_TYPE::isTrans, MM_CFG>;
};

}
#endif // _MATMUL_MACRO_DEF_H_